

from openai import OpenAI
import os
api_key = 'sk-bphodwvjqrzayelwjmbfvgmgwlzjbhpexxmvazkdemrlzyst'
api_url = 'https://api.siliconflow.cn/v1'
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"

model = 'Qwen/Qwen3-8B'
client = OpenAI(api_key=api_key, base_url=api_url)
messages = [
            {'role': 'system', 'content': '你是一个基于知识库的AI助手，请根据以下上下文回答问题。'},
            {'role': 'user', 'content': f"问题:{'你好'}"}
        ]

response = client.chat.completions.create(
            model=model,
            messages=messages,
            stream=True
        )

generated_text = ""
for chunk in response:
            if chunk.choices and chunk.choices[0].delta.content:
                generated_text += chunk.choices[0].delta.content
print(generated_text)